#include <iostream>
#include <thread>
#include <future>
#include <chrono>

int Add(int num1,int num2)
{
    std::cout<<"加法计算1111"<<std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(3));
    std::cout<<"加法计算2222"<<std::endl;
    return num1 + num2;
}

int main()
{
    std::cout<<"--------------------1-------------------" << std::endl;
    // std::launch::deferred 在执行get获取异步的结果的时候，才会执行异步操作
    // std::launch::async 内部创建工作线程，异步地完成任务
    std::future<int> result = std::async(std::launch::async,Add,11,22);
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout<<"--------------------2-------------------" << std::endl;
    result.get();
    std::cout<<"--------------------3-------------------" << std::endl;
    return 0;
}